// pages/movie/more/more.js
let app = getApp()
let utils = require("../../../utils/util.js")


Page({

  /**
   * 页面的初始数据
   */
  data: {
    data1:[],
    isemp:true,
    allurl:""
  },

  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function (options) {
    let that = this;
    let sy = options.catrgory
    this.setData({ dname: sy })
    let smurl = app.globalurl.globa
    let hoturl = ""
    switch (options.catrgory) {
      case "不为谁而作的歌 (Live)":
        hoturl = smurl + '/music/api/?key=523077333&cache=1&type=so&id=' + options.catrgory + '&size=hq';
        break;
      case "即将上映":
        hoturl = smurl + '/music/api/?key=523077333&cache=1&type=so&id=你瞒我瞒&size=hq';
        break;
      case "排行榜":
        hoturl = smurl + '/music/api/?key=523077333&cache=1&type=so&id=上心&size=hq';
        break;
    }
     //设置请求连接
     this.setData({
       allurl: hoturl
     })

    console.log("dd", hoturl)
    utils.http(hoturl, that.cak)
    //在当前页面显示导航条加载动画
    wx.showNavigationBarLoading();
  },
  cak: function (res) {
    let moview = []
    for (let idx in res.Body) {
      let subject = res.Body[idx]
      let title = subject.title
      if (title.length >= 6) { title = title.substring(0, 6) + "..." }
      let covimg = subject.pic
      let author = subject.author
      let ping = subject.size128
      let statr = utils.conver(ping)
      let aid = subject.vid
      let temp = {
        title: subject.title,
        covimg: subject.pic,
        author: author,
        statr: utils.conver(subject.size128),
        ping: ping,
        aid: subject.vid
      }
      moview.push(temp)
    }
    //判断是否第一次进入 添加数据
    if (!this.data.isemp){
      this.setData({
        data1: this.data.data1.concat(moview)
      })
    }else{
      this.setData({
        isemp: false
      })
    }
    this.setData({
      data1: moview.slice(0, 20)
    })
    // 在当前页面隐藏导航条加载动画
    wx.hideNavigationBarLoading()
  },
  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady: function () {
    //动态设置标题
    let that = this
    wx.setNavigationBarTitle({
      title: that.data.dname
    })
  },
  //页面上拉触底事件的处理函数 框架=》             //https://developers.weixin.qq.com/miniprogram/dev/reference/api/Page.html
  onReachBottom(){
    let a=1;
    let sp=(a+1)*20
    this.setData({
      // data1: moview.slice(0, sp)
      data1: this.data.data1
    })
  console.log("上拉加载")
  },
  // 是否开启当前页面下拉刷新。 框架=>页面配置
  onPullDownRefresh() {
    let that = this;
    console.log("是否开启当前页面下拉刷新")
    var ref=this.data.allurl
    this.data.data1=[]
    utils.http(ref, that.cak)


    wx.stopPullDownRefresh()
  }

})